package com.chis.ms;

import java.io.File;

/**
 * 
 * @Description  过滤文件，并移动
 * @Company zwx
 * @author wlj
 * @version 2020年02月28日
 */
public class FileNewpath {

    private static String srcpath = "E:\\2020文档\\重庆电子监管码导入\\0311\\二类苗20200311";
    private static String tarpath = "E:\\2020文档\\重庆电子监管码导入\\0311\\tarfiles\\";

    public static void main(String[] args) {
        traverseFolder(srcpath);
    }

    public static void traverseFolder(String path) {
        System.out.println(path);
        File file = new File(path);
        if (file.exists()) {
            File[] files = file.listFiles();
            if (null == files || files.length == 0) {
                return;
            } else {
                for (File file2 : files) {
                    if (file2.isDirectory()) {
                        traverseFolder(file2.getAbsolutePath());
                    } else {
                        if (file2.getAbsolutePath().endsWith(".zip") && file2.getAbsolutePath().contains("_")) {
                            String filename = file2.getAbsolutePath().substring((file2.getAbsolutePath().lastIndexOf("\\")));
                            File newName = new File(tarpath+filename);
                            file2.renameTo(newName);
                        }
                    }
                }
            }
        } else {
            System.out.println("文件不存在!");
        }
    }
}
